package com.qf.day02;

/**
 * @author lixu
 */
public class Test04 {

    private static Object a = 1;
    private static Object b = 2;

    public static void main(String[] args) {
        new MyThreadA().start();
        new MyThreadB().start();

    }
    static class MyThreadA extends Thread{

        @Override
        public void run() {
            synchronized (a){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (b){
                    System.out.println("A线程获取二把锁");
                }
            }
        }
    }
    static class MyThreadB extends Thread{

        @Override
        public void run() {
            synchronized (b){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (a){
                    System.out.println("B线程获取二把锁");
                }
            }
        }
    }
}